﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using JiveMessenger.CustomControls;
using JiveMessenger.Models;
using System.Diagnostics;
using JiveMessenger.ViewModels;
using GalaSoft.MvvmLight.Messaging;

namespace JiveMessenger.Views
{
    public partial class PrivateMessagePage : PhoneApplicationPage
    {
        public PrivateMessagePage()
        {
            InitializeComponent();
            //ProgressIndicator prog = new ProgressIndicator();
            //prog.IsIndeterminate = false;
            //prog.Text = "Jive Messenger";
            //prog.IsVisible = true;
            //SystemTray.SetProgressIndicator(this, prog);
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            ViewModelLocator.CleanupViewModelPrivateMessagePage();
            //App.Client.OpenPm = null;
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);


            if (e.NavigationMode == NavigationMode.New)
            {

                string loadedUserName;
                if (NavigationContext.QueryString.TryGetValue("userID", out loadedUserName))
                {
                    if (!string.IsNullOrEmpty(loadedUserName))
                    {
                        ((ViewModelPrivateMessagePage)this.DataContext).LoadUser(loadedUserName);
                    }
                }
            }
        }
    }
}